package org.linuxsogood.boot.grpc.server;

import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import org.linuxsogood.boot.grpc.Greeting;
import org.linuxsogood.boot.grpc.HelloWorldServiceGrpc;
import org.linuxsogood.boot.grpc.Person;
import org.lognet.springboot.grpc.GRpcService;

/**
 * @author liu.hongwei
 * @since 2020/11/10 17:46
 */
@GRpcService
@Slf4j
public class HelloWorldServiceImpl extends HelloWorldServiceGrpc.HelloWorldServiceImplBase {

    @Override
    public void sayHello(Person request, StreamObserver<Greeting> responseObserver) {
        log.info("server received {}", request);
        String message = "Hello " + request.getFirstName() + " " + request.getLastName() + "!";
        Greeting greeting = Greeting.newBuilder().setMessage(message).build();

        log.info("server responded {}", greeting);
        responseObserver.onNext(greeting);
        responseObserver.onCompleted();
    }
}
